﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Solitaire {
    public enum CardSuit {
        heart = 0, spade, diamond, club, joker
    }

    public enum CardRank {
        ace = 1, two = 2, three = 3,
        four = 4, five = 5, six = 6,
        seven = 7, eight = 8, nine = 9,
        ten = 10, jack = 11, queen = 12,
        king = 13, red = 14, black = 15
    }
    /// <summary>
    /// Stores the appearance and collision behavior of a tile.
    /// </summary>
    /// 

    class Card {
        Texture2D face, back;
        CardSuit suit;
        CardRank rank;
        public Rectangle rect;
        public bool FaceUp = false;
        public delegate void Comparison<Card>(Card a, Card b);
           
        int depth;

        public static int width = 71;
        public static int height = 96;

        public Card(CardSuit suit, CardRank rank) {
            this.suit = suit;
            this.rank = rank;
            this.rect = new Rectangle(0,0,Card.width,height);
        }

        public Card(bool black): this(CardSuit.joker,black?CardRank.black:CardRank.red){
        }

        public void LoadContent(ContentManager content) {
            face = content.Load<Texture2D>(string.Format("cards\\{0}_{1}", this.rank.ToString(), this.suit.ToString()));
            back = content.Load<Texture2D>("cards\\back");
        }

        public void flip() {
            FaceUp = FaceUp ? false : true;
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch) {
            if((face != null) && (back != null))
                spriteBatch.Draw(FaceUp ? face : back, rect, Color.White);
        }

        public void setPosition(Vector2 pos) {
            rect.X = (int)pos.X;
            rect.Y = (int)pos.Y;
        }

        public Vector2 getPosition() {
            return new Vector2((float)rect.X, (float)rect.Y);
        }

        public static int CompareByDepth(Card x, Card y) {
            return x.depth - y.depth;
        }

        public bool matches(Card c) {
            if ((this.depth == c.depth) &&
               (this.rank == c.rank) &&
               (this.suit == c.suit))
                return true;
            return false;
        }


    }
}
